package com.ruoyi.system.youshuda;

import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.zgl.youshuda.core.domain.MksLoginUser;
import com.zgl.youshuda.core.service.IMksAuthorInfoService;
import org.springframework.stereotype.Service;

/**
 * 将平台用户登录信息传递给 Java 图形化编程平台
 */
@Service
public class AssignMksLoginUser implements IMksAuthorInfoService {
    /**
     * 获取当前用户信息
     *
     * @return
     */
    @Override
    public MksLoginUser getUserInfo() {
        try{
            //获取平台用户信息
            LoginUser loginUser = SecurityUtils.getLoginUser();
            SysUser sysUser = loginUser.getUser();
            //创建返回Java 图形化编程平台用户登录对象
            return new MksLoginUser(sysUser.getUserId(), sysUser.getUserName(), sysUser.getNickName(), loginUser.getToken());
        }catch (Exception e){
            throw new ServiceException("无效的会话，请重新登录", HttpStatus.UNAUTHORIZED);
        }
    }

}
